<template>
  <div class="view-fill">
    <div class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        :title="title"
        @returnBack="$emit('returnBack')"
      >
        <template v-slot:full-button>
          <el-button
            v-if="
              $permission('pendWithTableKit:confirm') &&
              infoList.data.checkStatus === 1
            "
            @click="confirm"
            >确认</el-button
          >
          <el-button
            v-if="
              $permission('pendWithTableKit:refuse') &&
              infoList.data.checkStatus === 1
            "
            @click="refuse"
            >拒绝</el-button
          >
        </template>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('basic_information') }}</p>
          </div>
          <div class="model-panel-body">
            <basic-information :info="infoList"></basic-information>
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('detailInfo') }}</p>
          </div>
          <div class="model-panel-body">
            <div class="layui-card-body">
              <!-- 表格 -->
              <page-table
                :refresh="tableInfo.refresh"
                :init-curpage="tableInfo.initCurpage"
                v-model:data="tableInfo.data"
                :pager="false"
                :field-list="tableInfo.fieldList"
                :handle="tableInfo.handle"
                :check-box="false"
                :tab-index="true"
                :isDynamic="true"
              >
              </page-table>
            </div>
          </div>
        </div>
      </NewFullScreen>
    </div>
  </div>
</template>

<script setup name="details">
import BasicInformation from '@/components/BasicInformation/index'
import PageTable from '@/components/PageTable/index'
import { getCustomizeSetting } from '@/api/customize'
import {
  getWithTableKitCheckById,
  getWithTableKitDetailCheckAll,
  withTableKitCheckRefuse,
  withTableKitCheckConfirm,
} from '@/api/withTable.js'

const { proxy } = getCurrentInstance()
const emit = defineEmits()
const props = defineProps(['visible', 'id'])

const title = ref('待审核手术包详情')
const infoList = reactive({
  data: {},
  fieldList: [
    {
      label: '手术包名称',
      value: 'name',
    },
    {
      label: '手术包编码',
      value: 'code',
    },
    {
      label: '供应商名称',
      value: 'supplierName',
    },
    {
      label: '状态',
      value: 'checkStatusValue',
    },
    {
      label: '备注',
      value: 'remark',
      type: 'popover',
    },
  ],
})
const tableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  data: [],
  fieldList: [],
})
const filterInfo = reactive({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.id,
      },
    },
    queryParams: {},
  },
})

const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emit('update:visible', newValue) // 更新父组件visible
  },
})

let obj = {
  name: {
    label: '名称',
    value: 'name',
    componentType: 'input',
    show: false,
    hidden: true,
  },
}
tableInfo.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...obj,
})
getCustomize()

function ifRenderValue(row) {
  return (
    row.codeType !== 1 &&
    (infoList.data.checkStatus === 2 || infoList.data.checkStatus === 3)
  )
}
//确认
function confirm() {
  withTableKitCheckConfirm([props.id]).then((res) => {
    if (res && res.success) {
      getMain()
      getList()
    }
  })
}
//拒绝
function refuse() {
  withTableKitCheckRefuse([props.id]).then((res) => {
    if (res && res.success) {
      getMain()
      getList()
    }
  })
}
function getList() {
  getWithTableKitDetailCheckAll(filterInfo.query).then((resp) => {
    if (resp && resp.success) {
      tableInfo.data = resp.data
    }
  })
}
function getMain() {
  getWithTableKitCheckById(props.id).then((resp) => {
    if (resp && resp.success) {
      infoList.data = resp.data
    }
  })
}
function getCustomize() {
  let param = {
    tableKey:
      'withTableKitCheckDetail-com.slip.spd.entity.vo.withtable.WithTableKitDetailCheckVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.query.customizeUserVO = data
      let obj = proxy.$fn.setFieldList(tableInfo.fieldList, data.detail, true)
      tableInfo.fieldList = obj.fieldList
      getMain()
      getList()
    }
  })
}
</script>

<style scoped></style>
